package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihuRpc/internal/svc"
	"zhihu/zhihuRpc/zhihuRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReplyLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewReplyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReplyLogic {
	return &ReplyLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ReplyLogic) Reply(in *zhihuRpc.ReplyRequest) (*zhihuRpc.ReplyResponse, error) {
	// todo: add your logic here and delete this line

	reply := mysql.Reply{
		Content:    in.Content,
		UserId:     in.UserId,
		QuestionId: in.QuestionId,
	}

	mysql.DB.Debug().Create(&reply)

	return &zhihuRpc.ReplyResponse{
		Id: int64(reply.ID),
	}, nil
}
